# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=aptdec
pkgver=v1.8.0.r2.g7db2030
pkgrel=1
pkgdesc='NOAA APT satellite imagery decoder.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-radio')
url='https://github.com/Xerbo/aptdec'
license=('GPL-2.0-or-later')
depends=('libsndfile' 'libpng')
makedepends=('git' 'cmake')
source=("git+https://github.com/Xerbo/$pkgname.git"
        "git+https://github.com/cofyc/argparse.git")
sha512sums=('SKIP'
            'SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  git submodule init
  git config submodule.src/argparse.url "$srcdir/argparse"
  git -c protocol.file.allow=always submodule update

  sed -i 's/^cmake_minimum_required *(VERSION \([0-9]\+\(\.[0-9]\+\)\{0,2\}\)).*/cmake_minimum_required(VERSION 3.5)/' CMakeLists.txt
}

build() {
  cd $pkgname

  cmake -B build \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr

  make -C build
}

package() {
  cd $pkgname

  make -C build DESTDIR="$pkgdir" install
}

